<extend name="Public/base" />
<block name="content">
<script src="__STATIC__/aui-artDialog-9fd667e/dist/dialog.js"></script>
<script src="__STATIC__/aui-artDialog-9fd667e/dist/dialog-plus.js"></script>
<script src="__JS__/underscore.js"></script>
<link rel="stylesheet" href="__STATIC__/aui-artDialog-9fd667e/css/ui-dialog.css">
<script src="__JS__/jjhh.js?v={:C('TKE_VERSION')}"></script>

<style type="text/css">
	/*reset 模板内部表单样式 BEGIN*/
	.tpl_form .row-fluid{margin: 0;}
	.tpl_form .row-fluid .control-group{width: 150px;float: left;display:block;margin:0 15px 0 0;}
	.tpl_form .row-fluid .select-group{width: 150px;float: left;display: block;margin-right: 15px;}
	/*reset 模板内部表单样式 END*/
	.row-title{float: left;display:block;margin:5px; font-size:14px;width:100px;padding:0px 10px;border-left:2px solid #ccc;}
	.row-title-l2{margin-top:5px;}
	.input-text-group{width:150px;float: left;margin-left:31px;overflow: hidden;}
	.input-text-group label{float: left;padding:5px; font-size:14px;}
	.input-text-group input{float: left;width:120px;height: 14px;}

	.input-radio-group{}
	.input-radio-group label{padding:0 15px; margin-top:5px;}

	.indent{margin:5px 30px;}
	td{text-align: center;}
	.btn-view{position: fixed;top:100px;right:100px;background: rgba(0,0,0,0.6);color: #FFF;display: block;cursor: pointer;display: block;padding: 15px;}
	.btn-view:hover{color: #AAA;}
	#remarks{outline: none;resize:none;height:14px;line-height: 14px; overflow: hidden;width: 100%;min-width: 380px;}
</style>
<div id="content">
	<!-- 自由发挥区--开始 -->
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i class="icon-home"></i> 首页</a>
			<a href="{:U('ServiceSeat/myRecommend')}">坐席管理</a>
			<a href="{$nav_url}">{$nav_title}</a>
			<a class="current">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<!-- 增加住房信息 [模板]-->
		<script  type="text/template" id="tpl_add_house_info">
			<form class="tpl_form" id="j-add-house-info" way-data="house_info_add" way-persistent="false">
				<div class="row-fluid clearfix">
					<input type="hidden" name="customer_id" value="{$customer_detail.customer_id}" />
					<select required="required" name="province_id" class="select-group" id="j-select-province">
						<option value="0">请选择省</option>
					</select>
					<select required="required" name="city_id" class="select-group" disabled  id="j-select-city">
						<option value="0">请选择城市</option>
					</select>
					<select required="required" name="ward_id" class="select-group" disabled  id="j-select-ward">
						<option value="0">请选择区</option>
					</select>
					<select required="required" name="village_id" class="select-group" disabled  id="j-select-village">
						<option value="0">请选择居民区</option>
					</select>
				</div>
				<div class="row-fluid clearfix">
					<div class="control-group">
						<label class="control-label">入户时间</label>
						<div class="controls">
							<input readonly="readonly" maxlength="10" required="required" name="home_time" type="text" class="datepicker span12" placeholder="请输入入户时间">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">平米数</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="6" required="required" name="decoration_meter" class="span12" type="text" placeholder="请输入平米数">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">平米价格(元)</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="14" required="required" class="span12" name="house_price" type="text" placeholder="输入平米价格">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">装修时间</label>
						<div class="controls">
							<input  readonly="readonly"  maxlength="10" required="required" name="decoration_time" class="datepicker span12" type="text" placeholder="请输入装修时间">
						</div>
					</div>
				</div>
				<div class="row-fluid clearfix">
					<div class="control-group">
						<label class="control-label">装修预算(元)</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="14" required="required" name="decoration_budget" class="span12" type="text" placeholder="请输入装修预算">
						</div>
					</div>
				</div>
			</form>
		</script>
		<!-- /增加住房信息 [模板] -->

		<!-- 修改住房信息 [模板]-->
		<script type="text/template" id="tpl_edit_house_info">
			<form class="tpl_form" id="j-edit-house-info" way-data="house_info_edit" way-persistent="false">
				<input name="house_id" value="<%=house_id%>" type="hidden"/>
				<div class="row-fluid clearfix">
					<select class="select-group" data-default="<%=province_id%>" name="province_id" id="j-select-province" data-value="1" readonly="readonly">
						<option value="0">请选择省</option>
					</select>
					<select class="select-group" data-default="<%=city_id%>" name="city_id" disabled  id="j-select-city" readonly="readonly">
						<option value="0">请选择城市</option>
					</select>
					<select class="select-group" data-default="<%=ward_id%>" name="ward_id" disabled  id="j-select-ward" readonly="readonly">
						<option value="0">请选择区</option>
					</select>
					<select class="select-group" data-default="<%=village_id%>" name="village_id" disabled  id="j-select-village">
						<option value="0">请选择居民区</option>
					</select>
				</div>
				<div class="row-fluid clearfix">
					<div class="control-group">
						<label class="control-label">入户时间</label>
						<div class="controls">
							<input readonly="readonly"  maxlength="10" name="home_time" value="<%=home_time%>" type="text" class="datepicker span12" placeholder="请输入入户时间">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">平米数</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="6" value="<%=decoration_meter%>" name="decoration_meter" class="span12" type="text" placeholder="请输入平米数">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">平米价格(元)</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="14" value="<%=house_price%>" class="span12" name="house_price" type="text" placeholder="输入平米价格">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">装修时间</label>
						<div class="controls">
							<input  readonly="readonly" maxlength="10" value="<%=decoration_time%>" name="decoration_time" class="datepicker span12" type="text" placeholder="请输入装修时间">
						</div>
					</div>
				</div>
				<div class="row-fluid clearfix">
					<div class="control-group">
						<label class="control-label">装修预算(元)</label>
						<div class="controls">
							<input  onblur="value=value.replace(/\D*$/,'')" onkeyup="value=value.replace(/\D*$/,'')"  maxlength="14" value="<%=decoration_budget%>" name="decoration_budget" class="span12" type="text" placeholder="请输入装修预算">
						</div>
					</div>
				</div>
			</form>
		</script>
		<!-- /修改住房信息 [模板] -->

		<!-- 住房信息表格 -->
		<script type="text/template" id="tpl_house_info">
			<tr>
				<td name="province_id" data-id="<%=province_id%>"><%=province_name%></td>
				<td name="city_id" data-id="<%=city_id%>"><%=city_name%></td>
				<td name="ward_id" data-id="<%=ward_id%>"><%=ward_name%></td>
				<td name="village_id" data-id="<%=village_id%>"><%=village_name%></td>
				<td name="home_time"><%=home_time%></td>
				<td name="decoration_meter"><%=decoration_meter%></td>
				<td name="house_price"><%=house_price%></td>
				<td name="decoration_time"><%=decoration_time%></td>
				<td name="decoration_budget"><%=decoration_budget%></td>
				<td name="house_id" data-id="<%=id%>">
					<a data-id="<%=id%>" class="btn btn-small btn-warning btn-edit-house-info">修改</a>
					<a data-id="<%=id%>" class="btn btn-small btn-danger btn-del-house-info">删除</a>
				</td>
			</tr>
		</script>
		<!-- /住房信息表格 -->

		<!-- 活动列表表格 -->
		<script type="text/template" id="tpl_activity_list">
			<table class="table table-bordered">
				<tr>
					<td>活动名</td>
					<td>推广人</td>
					<td>票别</td>
					<td>报名时间</td>
					<td>签到</td>
					<td>签单</td>
				</tr>
				<% for (k in data) { %>
				<% var item = data[k] %>
				<tr>
					<td><%=item.activity_name%></td>
					<td><%=item.generalize_member_name%></td>
					<td><%=item.ticket_level_text%></td>
					<td><%=item.join_time%></td>
					<td><%=item.is_signin%></td>
					<td><%=item.is_order%></td>
				</tr>
				<% } %>
			</table>
		</script>
		<!-- /活动列表表格 -->

		<!-- 稍后拨打popup -->
		<script type="text/template" id="tpl_popup_later">
			<div class="later" id="call_time_content">
				<div class="controls">
					<input style="width:248px;"  name="later_call_time" type="text" class="datepicker" placeholder="请输入稍后拨打时间">
				</div>	
			</div>	
		</script>	
		<!-- /稍后拨打popup -->
		
		<if condition="$Think.session.last_phone neq ''"><h5 class="text-info">上次呼叫电话：{$Think.session.last_phone}</h5><else/><br /></if>
		<form id="customer" method="post" >

			<!-- 按钮 -->
			<div class="clearfix">
				<if condition="(int)I('get.origin')!=6">
					<div class="btn btn-info" id="call_time"><i class="icon-adjust"></i> 稍后拨打</div>
				</if>
				<!-- button class="btn btn-large btn-inverse" data="3" name="submit_customer"><i class="icon-remove"></i> 跳过, 拨打下一个</button-->
				<div class="btn btn-danger" id="call_me"><i class="icon-headphones"></i> 立即拨打: {:getCustomerName($customer_detail['customer_id'])}<!--{:substr_replace(getCustomerName($customer_detail['customer_id']),'***',4,3)}--></div>
				<if condition="$customer_detail['is_valid']==0">
					<button class="btn btn-warning fr" data="2" name="submit_customer"><i class="icon-tag"></i> 无效, 拨打下一个</button>
				<else/>
					<div class="btn btn-danger fr">已经被设置为无效用户</div>
				</if>
			</div>
			<!-- /按钮 -->
			<input type="hidden" id="submit_type" name="submit_type" value="">


			<!-- 操作记录 -->
			<h6 class="text-info"><i class="icon-th-list"></i> 操作记录</h6>
			<if condition="$last_call_time">
			<p class="alert alert-error">上次通话时间:{$last_call_time|date='Y-m-d H:i:s',###}</p>
			</if>
			<div class="m-table" id="operation_log_list">
				<p class="muted">加载中...</p>
			</div>
			<!--/ 操作记录 -->
			
			<!-- 客户信息 -->
			<style type="text/css">
			.m-client{margin:15px 5px;}
			.m-client input{height: 14px;}
			.m-client .control-group{overflow: hidden;margin-right: 5px;}
			.m-client .control-group label{float: left;padding-right: 10px;}
			.m-client .control-group .controls{float: left;}

			.m-client .u-contact{display: none;}
			</style>
			<h6 class="text-info"><i class="icon-user"></i> 客户信息</h6>
			<div class="m-client">
				<!-- <p class="alert alert-success">当前拨打: 13613655671</p> -->
				<!-- Name: <span way-data="form_data.demand_content_id"></span> -->
				<!-- 姓名&性别 -->
				<input name="customer_id" type="hidden" value="{$customer_detail.customer_id}"/>
				<input name="is_valid" id="is_valid" type="hidden" value="{$customer_detail.is_valid}"/>
				<div class="row-fluid">
					<div class="control-group span3">
						<label class="control-label">姓名</label>
						<div class="controls">
							<input type="text" placeholder="请输入姓名" maxlenght="20" name="customer_name" value="{$customer_detail.customer_name|htmlspecialchars}">
						</div>
					</div>
					<div class="control-group span3">
						<label class="radio">
							<input name="sex" type="radio" value="1" <if condition="$customer_detail['sex']==1">checked</if>> 男
						</label>
						<label class="radio">
							<input name="sex" type="radio" value="2" <if condition="$customer_detail['sex']==2">checked</if>> 女
						</label>
						<label class="radio">
							<input name="sex" type="radio" value="0" <if condition="$customer_detail['sex']==0">checked</if>> 未知
						</label>
					</div>	

					<div class="span3">
						<a id="j-contact-toggle" class="btn btn-link btn-mini">点击显示更多联系方式↓</a>
					</div>
					<script type="text/javascript">
					$("#j-contact-toggle").on("click", function(){
						$("#j-contact").fadeIn(500);
					});
					</script>
				</div>
				<!-- /姓名&性别 -->
				<!-- 联系方式 -->
				<div class="row-fluid u-contact" id="j-contact">
					<div class="control-group pull-left">
						<label class="control-label">QQ</label>
						<div class="controls">
							<input type="text" placeholder="请输入QQ" name="qq" maxlength="12" value="{$customer_detail.qq|htmlspecialchars}">
						</div>
					</div>	
					<div class="control-group pull-left">
						<label class="control-label">微信</label>
						<div class="controls">
							<input type="text" placeholder="请输入微信" name="wechat"maxlength="30" value="{$customer_detail.wechat|htmlspecialchars}">
						</div>
					</div>
					<div class="control-group pull-left">
						<label class="control-label">邮箱</label>
						<div class="controls">
							<input type="email" placeholder="请输入邮箱" name="mailbox" maxlength="30" value="{$customer_detail.mailbox|htmlspecialchars}">
						</div>
					</div>
					<div class="control-group pull-left">
						<label class="control-label">电话</label>
						<div class="controls">
							<input type="text" placeholder="请输入其他手机/座机" name="phone_number" maxlength="20" value="{$customer_detail.phone_number|htmlspecialchars}">
						</div>
					</div>
				</div>
				<!-- /联系方式 -->
				<!-- 备注 -->
				<div class="row-fluid">
					<div class="control-group">
						<label class="control-label">备注</label>
						<div class="controls">
							<textarea placeholder="请输入备注" name="remark" id="remarks">{$customer_detail.remark|htmlspecialchars}</textarea>
						</div>
					</div>						
				</div>
				<script type="text/javascript">
					$("#remarks").focus(function() {
						$(this).stop().animate({"height": "100px", "width": "560px"}, 300);
					}).blur(function() {
						$(this).stop().animate({"height": "14px", "width": "380px"}, 300);
					});
				</script>
				<!-- /备注 -->

				<!-- 房产信息 -->
				<div class="row-fluid">
					<div class="span12">
						<h6 class="text-info"><i class="icon-home"></i> 房产信息</h6>
						<a class="btn btn-add-house-info btn-small btn-success pull-left" id="j-btn-add-house-info"><i class="icon-plus"></i> 新增房产信息</a>
						<div style="clear:both"  class="m-table" id="house_list">
							<p class="muted">加载中...</p>
						</div>
					</div>
				</div>
				<!-- /房产信息 -->
				
				<!-- 装修需求 -->
				<div class="row-fluid" id="demand_list"></div>
				<!-- 装修需求 -->
				<button  class="btn btn-primary" style="margin-left:40%;"><i class="icon-ok"></i> 保存客户信息及装修需求</button>


				<!-- 正在推荐活动 -->
				<h6 class="text-info"><i class="icon-star"></i> 正在推荐活动</h6>
				<div class="clearfix"></div>
				<div id="j-activity-join">
					<volist name="activity" id="vo">
					<a data-url="{:U('activityJoin',array('activity_id'=>$vo['activity_id'],'id'=>$customer_detail['customer_id']))}" target="_blank" class="btn  btn-small btn-danger popup-activity-join" style="margin-right:10px">
						{$vo.activity_name|htmlspecialchars}
					</a>
					</volist>
				</div>
				<!--/ 正在推荐活动 -->
				<!-- 已报名活动 -->
				<h6 class="text-info"><i class="icon-ok"></i> 已报名活动</h6>
				<div>
					<button data-loading-text="正在加载..." id="j-loading-activity-more"  type="button" class="btn btn-small btn-info"><i class="icon-globe"></i> 获取已报名活动</button>
					<div id="j-loading-activity-list"></div>
				</div>
				<!--/ 已报名活动 -->
			</div>
			<!-- /客户信息 -->
		</form>
		<button  class="btn btn-primary" style="margin-left:40%;"  data="4" name="submit_customer"><i class="icon-ok"></i>拨打下一个</button>
	</div>

	<!-- 自由发挥区--结束 -->
</div>
<div id="value"></div>
<!-- 自由发挥区--开始 -->
<script type="text/javascript">
$(function(){
	window.dialog = dialog;

	// 弹出报名页面
	$("#j-activity-join").on("click", "a.popup-activity-join", function(){
		var url = $(this).data("url");
		var d = dialog({
			"width": 640,
			"url": url,
			"title": '加载中...',
			"oniframeload": function () {
				d.title("活动报名");
			}
		}).showModal();
	});
	
	//稍后拨打
	$("#call_time").click(function(){
		var template = $("#tpl_popup_later").html();
		var URL_CALL_LATER = "{:U('ServiceSeat/'.$c,$param)}";
		dialog({
			"title": "提示",
			"content": template,
			"okValue": "<i class=\" icon-adjust\"></i> 保存, 拨打下一个",
			"ok": function(){
				var later_time = $("#call_time_content").val();
				$.ajax({
					"url": URL_CALL_LATER,
					"type": "POST",
					"dataType": "json",
					"data": "later_call_time="+$("input[name=later_call_time]").val()+"&submit_type=1&customer_id={$customer_detail['customer_id']}",
				}).done(function(json) {
					if (1 == json.status){
						var d = dialog({
							"title": "提示",
							"content": json.info
						}).showModal();
						setTimeout(function (){
							d.remove().close();
							location.href = json.url;
						}, 2000);
					} else {
						dialog({
							"title": "提示",
							"content": json.info
						}).showModal();
					}
				});
			}
		}).showModal();
		//初始化日期选择器
	    $(".ui-dialog").find(".datepicker").datetimepicker({
	        format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true
	    });
	});

	//保存个人资料
	$("form[id=customer]").submit(function(){
		//锁定提交按钮
		$(this).attr('disabled',true);
		var self = $('form[id=customer]');
		$.ajax({
	        url:"{:U('ServiceSeat/saveCustomer')}",
	        type:"post",
	        dataType:'json',
	        data:self.serialize(),
	        success:function(data){
	        	if(data.status == 1){
	                tke_alert(data.info,'alert-success');
	            } else {
	                tke_alert(data.info,'alert-error');
	                $(this).attr('disabled',false);
	            }
	        },
	        timeout:5000, //超时时间，考虑到网络问题，5秒还是比较合理的
			complete:function(XHR,TextStatus){
			    if(TextStatus=='timeout'){
			    	alert('访问错误或访问超时，请检查你的网络是否出现问题')
			    }
			    $(this).attr('disabled',false);
			}
	    });
        return false;
	});
	
	//保存并拨打下一个
	$("button[name=submit_customer]").click(function(){
		var submit_type = $(this).attr("data");
		if(submit_type==2){
			if(!confirm("你确定把此用户修改为无效用户么")){
				return false;
			}
		}
		//锁定提交按钮
		$(this).attr('disabled',true);
		var self = $('form[id=customer]');
		$.ajax({
	        url:"{:U('ServiceSeat/'.$c,$param)}",
	        type:"post",
	        dataType:'json',
	        data:"later_call_time="+$("input[name=later_call_time]").val()+"&submit_type="+submit_type+"&customer_id="+{$customer_detail['customer_id']},
	        success:function(data){
	        	if(data.status == 1){
					tke_alert(data.info,'alert-success');
					setTimeout(function(){
						window.location.href = data.url;
					},1000);
				} else {
					tke_alert(data.info,'alert-error');
					$("button[name=submit_customer]").attr('disabled',false);
				}
	        },
	        timeout:5000, //超时时间，考虑到网络问题，5秒还是比较合理的
			complete:function(XHR,TextStatus){
			    if(TextStatus=='timeout'){
			    	alert('访问错误或访问超时，请检查你的网络是否出现问题')
			    }
			    $(this).attr('disabled',false);
			}
	    });
	});

	//需求加载
	$.ajax({ url: "{:U('ServiceStatistics/getDemandList')}", data: { demand_value : '{$demand_value}'} , success: function(data){
		if('' != data){
        	$('#demand_list').html(data).hide().fadeIn(500);
		}
      	//初始化控件
        var IS_INIT = 1;
     	// 全选
        $(".checkbox-all").bind("click",function(){
            $(this).nextAll("div.checkbox-group").children("label").children("input").prop("checked", true);
        });
        // 反选
        $(".checkbox-opposite").bind("click",function(){
            $(this).nextAll("div.checkbox-group").children("label").children("input[type=checkbox]").each(function(e) {
                if ($(this).is(":checked")) {
                    $(this).prop("checked", false);
                }else{
                    $(this).prop("checked", true);
                }
            });
        });
	}});

	$.ajax({ url: "{:U('ServiceSeat/getOperationLog',array('id'=>$customer_detail['customer_id']))}", data: {} , success: function(data){
    	if('' != data){
        	$('#operation_log_list').html(data).hide().fadeIn(300);
    	}
	}});

	$.ajax({ url: "{:U('ServiceSeat/getHouseList',array('id'=>$customer_detail['customer_id']))}", data: {} , success: function(data){
    	if('' != data){
        	$('#house_list').html(data).hide().fadeIn(300);
    	}
	}});

	//初始化日期选择器
    $(".datepicker").datetimepicker({
        format: 'yyyy-mm-dd hh:ii:ss',
        autoclose: true,
        todayBtn: true
    });

	// 获取更多活动
	var $btn_more = $("#j-loading-activity-more");
	$btn_more.click(function() {
		var URL_LOADING_ACTIVITY_MORE = "{:U('/ServiceSeat/getHistoryActivity',array('id'=>$customer_detail['customer_id']))}";
		$(this).button('loading');
		$.ajax({
			"url": URL_LOADING_ACTIVITY_MORE,
			"type": "GET",
			"dataType": "json"
		}).done(function(json) {
			if (1 == json.status) {
				var template = _.template($("#tpl_activity_list").html());
				var html = template(json);
				$btn_more.button('reset');
				$("#j-loading-activity-list").html(html);
			} else {
				$btn_more.button('reset');
				$("#j-loading-activity-list").html(json.info);
			}
		});
	});

	var url_area = {
		"province" :"{:U('ServiceApi/getProvinceList')}",
        "city" :"{:U('ServiceApi/getProvinceCityList')}",
        "ward": "{:U('ServiceApi/getCityWard')}",
        "village": "{:U('ServiceApi/getWardVillage')}"
    }

	// 新增房产信息
    $("#j-btn-add-house-info").click(function(){
	    var html = $("#tpl_add_house_info").html();
	    var d_init = dialog({
	    	"title": "新增房产信息",
	    	"content": html,
	    	"okValue": "保存",
	    	"fixed": true,
	    	"ok": function() {
	    		var d_loading = dialog({"title": "加载中..."}).showModal();
	    		var URL_ADD_HOUSE_INFO = "{:U('ServiceSeat/saveHouse',array('customer_id'=>$customer_detail['customer_id']))}";
	    		$.ajax({
	    			"url": URL_ADD_HOUSE_INFO,
	    			"type": "POST",
	    			"dataType": "json",
	    			"data": $("#j-add-house-info").serialize()
	    		}).done(function(json) {
	    			d_loading.remove().close();
	    			if (1 == json.status) {
	    				// 追加到房产表

	    				var form_data = {
	    					"province_id": $("#j-add-house-info").find("select[name=province_id]").val(),
	    					"province_name": $("#j-add-house-info").find("select[name=province_id]").children("option:selected").html(),
	    					"city_id": $("#j-add-house-info").find("select[name=city_id]").val(),
	    					"city_name": $("#j-add-house-info").find("select[name=city_id]").children("option:selected").html(),
	    					"ward_id": $("#j-add-house-info").find("select[name=ward_id]").val(),
	    					"ward_name": $("#j-add-house-info").find("select[name=ward_id]").children("option:selected").html(),
	    					"village_id": $("#j-add-house-info").find("select[name=village_id]").val(),
	    					"village_name": $("#j-add-house-info").find("select[name=village_id]").children("option:selected").html(),
	    					"home_time": $("input[name=home_time]").val(),
	    					"decoration_meter": $("input[name=decoration_meter]").val(),
	    					"house_price": $("input[name=house_price]").val(),
	    					"decoration_time": $("input[name=decoration_time]").val(),
	    					"decoration_budget": $("input[name=decoration_budget]").val(),
	    					"id":json.data.id
	    				};

	    				var template = _.template($("#tpl_house_info").html());
	    				var html = template(form_data);

	    				$("#j-table-house-info").append(html);

	    				var d = dialog({
	    					"title": "提示",
	    					"content": json.info
	    				}).showModal();
	    				setTimeout(function(){
	    					d.remove().close();
	    				}, 2000);
	    				d_init.remove().close();
	    			} else {
	    				dialog({
	    					"title": "提示",
	    					"content": json.info
	    				}).showModal();

	    			}
	    		});
	    		return false;
	    	}
	    }).showModal();
	    // 初始化select
	    jjhh_select_area(url_area, 4);
	    //初始化日期选择器
	    $(".datepicker").datetimepicker({
	        format: 'yyyy-mm-dd',
	        minView: 'month',
	        autoclose: true,
	        todayBtn: true
	    });
    });

	// 修改房产信息
	$(document).on("click", ".btn-edit-house-info", function(){
		// ==读取房产信息
		var customer_id = $("#j-customer-id").val();
		var $this = $(this);
		var $tr   = $this.parent().parent();
		function _get_house_info(callback) {

			var data = {
				"province_id": $tr.children("td[name=province_id]").data("id"),
				"city_id": $tr.children("td[name=city_id]").data("id"),
				"ward_id": $tr.children("td[name=ward_id]").data("id"),
				"village_id": $tr.children("td[name=village_id]").data("id"),
				"home_time": $tr.children("td[name=home_time]").html(),
				"decoration_meter": $tr.children("td[name=decoration_meter]").html(),
				"house_price": $tr.children("td[name=house_price]").html(),
				"decoration_time": $tr.children("td[name=decoration_time]").html(),
				"decoration_budget": $tr.children("td[name=decoration_budget]").html(),
				"house_id": $tr.children("td[name=house_id]").data("id")
			};
			callback(data);
		}
		// ==控制
		_get_house_info(function(data) {
			var template = _.template($("#tpl_edit_house_info").html());
			var html = template(data);
		    var d_init = dialog({
		    	"title": "修改房产信息",
		    	"content": html,
		    	"okValue": "保存",
		    	"fixed": true,
		    	"ok": function() {
		    		var d_loading = dialog({"title": "加载中..."}).showModal();
		    		var URL_EDIT_HOUSE_INFO = "{:U('ServiceSeat/saveHouse',array('customer_id'=>$customer_detail['customer_id']))}";
		    		$.ajax({
		    			"url": URL_EDIT_HOUSE_INFO,
		    			"type": "POST",
		    			"dataType": "json",
		    			"data": $("#j-edit-house-info").serialize()
		    		}).done(function(json) {
		    			d_loading.remove().close();
		    			if (1 == json.status) {
		    				var d = dialog({
		    					"title": "提示",
		    					"content": json.info
		    				}).showModal();
		    				// 省

		    				var province_name = $("#j-edit-house-info").find("#j-select-province>option:selected").html();
		    				var province_id   = $("#j-edit-house-info").find("#j-select-province").val();
		    				$tr.children("td[name=province_id]").html(province_name).data("id", province_id);
		    				// 市
		    				var city_name = $("#j-edit-house-info").find("#j-select-city>option:selected").html();
		    				var city_id   = $("#j-edit-house-info").find("#j-select-city").val();
		    				$tr.children("td[name=city_id]").html(city_name).data("id", city_id);
		    				// 区
		    				var ward_name = $("#j-edit-house-info").find("#j-select-ward>option:selected").html();
		    				var ward_id   = $("#j-edit-house-info").find("#j-select-ward").val();
		    				$tr.children("td[name=ward_id]").html(ward_name).data("id", ward_id);
		    				// 县
		    				var village_name = $("#j-edit-house-info").find("#j-select-village>option:selected").html();
		    				var village_id   = $("#j-edit-house-info").find("#j-select-village").val();
		    				$tr.children("td[name=village_id]").html(village_name).data("id", village_id);

		    				// 交房时间
							$tr.children("td[name=home_time]").html($("#j-edit-house-info").find("input[name=home_time]").val());
							// 平米
							$tr.children("td[name=decoration_meter]").html($("#j-edit-house-info").find("input[name=decoration_meter]").val());
							// 平米价格
							$tr.children("td[name=house_price]").html($("#j-edit-house-info").find("input[name=house_price]").val());
							// 装修时间
							$tr.children("td[name=decoration_time]").html($("#j-edit-house-info").find("input[name=decoration_time]").val());
							// 装修预算
							$tr.children("td[name=decoration_budget]").html($("#j-edit-house-info").find("input[name=decoration_budget]").val());

		    				setTimeout(function(){
		    					d.remove().close();
		    				}, 2000);
		    				d_init.remove().close();
		    			} else {
		    				dialog({
		    					"title": "提示",
		    					"content": json.info
		    				}).showModal();
		    			}
		    		});
		    		return false;
		    	}
		    }).showModal();
		    // 初始化select
		    jjhh_select_area(url_area, 4);
		    //初始化日期选择器
		    $(".datepicker").datetimepicker({
		        format: 'yyyy-mm-dd',
		        minView: 'month',
		        autoclose: true,
		        todayBtn: true
		    });

		});
	});


	// 删除房产信息
	$(document).on("click", ".btn-del-house-info", function() {
		var id = $(this).data("id");
		var $tr = $(this).parent().parent();
		var d_loading = dialog({"title": "加载中..."}).showModal();
		var URL_DEL_HOUSE_INFO = "{:U('ServiceSeat/delHouse',array('customer_id'=>$customer_detail['customer_id']))}";

		$.ajax({
			"url": URL_DEL_HOUSE_INFO,
			"type": "POST",
			"dataType": "json",
			"data": {house_id:id}
		}).done(function(json) {
			d_loading.remove().close();
			if (1 == json.status) {
				var d = dialog({
					"title": "提示",
					"content": json.info
				}).showModal();
				setTimeout(function(){
					d.remove().close();
					$tr.fadeOut(500);
				}, 2000);

			} else {
				dialog({
					"title": "提示",
					"content": json.info
				}).showModal();
			}
		});
	});


// == END ==
});



//导航高亮
highlight_subnav("{$nav_url}");
</script>
<!-- 自由发挥区--结束 -->
</div>
</block>
